package _05_二叉树;

public class _230_二叉搜索树中第K小的元素 {

    int k;

    int findEle = -1;

    public int kthSmallest(TreeNode root, int k) {
        this.k = k;
        midTra(root);
        return findEle;
    }

    public void midTra(TreeNode treeNode) {
        if (treeNode == null || findEle != -1) {
            return;
        }
        midTra(treeNode.left);
        if (--k == 0) {
            findEle = treeNode.val;
        }
        if (findEle != -1) return;
        midTra(treeNode.right);
    }
}
